A combination of If and Else statements. ElseIf behaves like an If statement in another If statement.
When an If statement evaluates to False, the ElseIf statement can evaluate an alternate condition and run a different block of statements if the alternate condition is True. An If statement can include several ElseIf statements.
Tip: The Select...Case statement is similar to the ElseIf statement and may be easier to use when evaluating a condition with several possible results.
Syntax
If Condition Then
[Statements]
[ElseIf Condition-n Then
[ElseIfStatements]]
End If
Arguments
| Argument | Description |
|---|---|
| Condition-n | Numeric or string expression that evaluates to True or False. For example, a > b, a < b, a = b, or a <> b. Null conditions are treated as False. |
| ElseIfStatements | One or more statements to run if the associated Condition-n is True. |
Keyword View notes
The condition to evaluate is displayed in the Information column.
Example
currentHour = Hour(Now())
Print("Time of day is ")
If (6 <= currentHour) and (currentHour < 12) Then
PrintLn("morning")
ElseIf (12 <= currentHour) and (currentHour < 18) Then
PrintLn("afternoon")
ElseIf (18 <= currentHour) and (currentHour < 24) Then
PrintLn("evening")
Else
PrintLn("night")
End If